<?php
include  '../loginCheck.php';
include  '../Util.php';
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
        <title>Downloads</title>
        <link rel="stylesheet" type="text/css" href="view.css" media="all"/>
        <script type="text/javascript" src="view.js"></script>

    </head>
    <body id="main_body" >

        <img id="top" src="top.png" alt=""/>
        <div id="form_container">

            <h1>
                <?php
                include  'menu.php';
                ?>
            </h1>
            <form id="form_144190" class="appnitro" enctype="multipart/form-data" method="post" action="../adminResolveDownload.php">
                <div class="form_description">
                    <h2><a href="download.php">New Downloads</a> | <a href="downloadDelete.php">Deleting Downloads</a> | <a href="downloadEdit.php">Edit Downloads</a></h2>
                    <p>You are editing downloads. Downloads from section Main do not edit other cell than File!</p>
                </div>
                <?php

                if (!isset($_GET['textId'])) {
                    $link = Util::getLink();?>
                <ul>
                    <li id="li_1" >
                        <label class="description" for="element_1">Downloads</label>
                        <div>

                                <?php

                                for ($i = 1; $i < 4; $i++) {
                                    $query0 = sprintf(Util::$downloadSection_select_nameById,
                                        mysql_real_escape_string($i)
                                    );

                                    $result2 = mysql_query($query0);

                                    if (!$result2) {
                                        die('Could not query:' . mysql_error() . '<br>' . $query);
                                    }
                                    $row = mysql_fetch_assoc($result2);

                                    $sectionArray[$i] = $row['name'];
                                }

                                $query = sprintf(Util::$select_jornakDestination,
                                    mysql_real_escape_string("4")
                                );

                                $result = mysql_query($query);

                                if (!$result) {
                                    die('Could not query:' . mysql_error() . '<br>' . $query);
                                }
                                $i = 1;
                                while ($row = mysql_fetch_assoc($result)) {
                                    $query = sprintf(Util::$select_jornakText,
                                        mysql_real_escape_string($row['textid'])
                                    );
                                    $result2 = mysql_query($query);
                                    if (!$result2) {
                                        die('Could not query:' . mysql_error() . '<br>' . $query);
                                    }
                                    $row2 = mysql_fetch_assoc($result2);
                                    echo '<input id="element_1_'.$i.'" name="element_1" class="element radio" type="radio" value="'.$row['textid'].'" />';
                                    echo '<label class="choice" for="element_1_'.$i.'">'. $sectionArray[$row2['list']] .'_'.  $row2['header'].'</label>';
                                    $i++;
                                }
                                echo '<input type="hidden" name="count" value="'.$i.'" />';
                                Util::closeLink($link);?>
                        </div><p class="guidelines" id="guide_1"><small>Chose download to edit.</small></p>
                    </li>
                </ul>
                <?php
                }else {
                    $link = Util::getLink();

                    $query = sprintf(Util::$select_jornakText,
                        mysql_real_escape_string($_GET["textId"])
                    );
                    $result = mysql_query($query);

                    if (!$result) {
                        die('Could not query:' . mysql_error() . '<br>' . $query);
                    }
                    $row = mysql_fetch_assoc($result);
                    ?>
                <ul >
                    <li id="li_1" >
                        <label class="description" for="element_1">Download headline</label>
                        <div>
                            <input id="element_1" name="element_1" class="element text medium" type="text" maxlength="255" value="<?php echo $row['header'] ?>"/>
                        </div><p class="guidelines" id="guide_1"><small>Download headline.</small></p>
                    </li>
                    <li id="li_2" >
                        <label class="description" for="element_2">Chose download section </label>
                        <div>
                            <select class="element select medium" id="element_2" name="element_2">
                                <option value="1" <?php if ($row['list']==1 ) echo ' selected="selected"'; ?>>Objects</option>
                                <option value="2" <?php if ($row['list']==2 ) echo ' selected="selected"'; ?>>Scenes</option>
                                <option value="3" <?php if ($row['list']==3 ) echo ' selected="selected"'; ?>>Main</option>
                            </select>
                        </div><p class="guidelines" id="guide_2"><small>Your uploaded file will appear in chosed section.</small></p>
                    </li>
                    <li id="li_3" >
                        <label class="description" for="element_3">File </label>
                        <div>
                            <input id="element_3" name="element_3" class="element text medium" type="text" maxlength="255" value="<?php echo stripslashes($row['text']); ?>"/>
                        </div> <p class="guidelines" id="guide_3"><small>Upload file. Upload it via ftp to www/admin/form/upload then write file name only. Example /File.jpg. (the file name is case sensitive)</small></p>
                    </li>
                        <?php Util::closeLink($link);} ?>
                    <li class="buttons">
                        <input type="hidden" name="form_id" value="144190" />

                        <input id="saveForm" class="button_text" type="submit" name="submit" value="Edit download" />
                    </li>
                </ul>
                <input type="hidden" name="form_type" value="4" />
                <?php if (isset($_GET['textId'])) { ?>
                <input type="hidden" name="edit" value="true" />
                <input type="hidden" name="oldFile" value="<?php echo $row['text']; ?>" />
                <input type="hidden" name="oldTextId" value="<?php echo $row['id']; ?>" />
                <?php }else { ?>
                <input type="hidden" name="noTextId" value="true" />
                <?php } ?>
            </form>
            <div id="footer">

            </div>
        </div>
        <img id="bottom" src="bottom.png" alt=""/>
    </body>
</html>